﻿g_Timestamp = 1325372400 -- Nowy rok

days = 0
hours = 0
minutes = 0
seconds = 0
txt = "nic"
launched = false
function formatDate(d) -- Konwersja sekundy -> dni, godziny, minuty, sekundy
h = math.floor(d / 3600)
m = math.floor(d % 3600 / 60)
s = math.floor(d % 3600 % 60)
if #tostring(h) < 2 then
	h = "0"..tostring(h)
elseif #tostring(m) < 2 then
	m = "0"..tostring(m)
elseif #tostring(s) < 2 then
	s = "0"..tostring(s)
end
return h, m, s
end


local scX, scY = guiGetScreenSize()
--[[
function drawText()
	if txt == "nic" then
		
		dxDrawText( "Do sylwestra pozostalo: "..hours.."h "..minutes.."m "..seconds.."s", 1, scY-29,0,scY-30,0xFF000000, 2, "arial" )
		dxDrawText( "Do sylwestra pozostalo: "..hours.."h "..minutes.."m "..seconds.."s", 0, scY-30,0,scY-30,tocolor(184,3,255), 2, "arial")
	else
		dxDrawText( txt, 1, scY-29,0,scY-30,0xFF000000, 2, "arial" )
		dxDrawText(	txt, 0, scY-30,0,scY-30,tocolor(184,3,255), 2, "arial")		
	end
end

addEventHandler("onClientRender", root, drawText)

function refresh()
	local realTimestamp = getRealTime().timestamp
	if (g_Timestamp - realTimestamp) <= 0 then
		txt = "Szczesliwego nowego roku! :)"
	else
		hours, minutes, seconds = formatDate(g_Timestamp - realTimestamp)
	end
end

setTimer(refresh, 100,0)
]]

url = "http://stream.epicradio.co.uk:8000/live"
function playRadio()
	if snd then stopSound(snd) end
	for k,v in pairs(getElementsByType("url")) do
		url = getElementData(v, "url")
	end
	snd = playSound3D(url,-2329.36011, -1614.08606, 490.7175) 
	setSoundMaxDistance(snd, 500)
end
playRadio()
addEvent("refreshRadio", true)
addEventHandler("refreshRadio", root, playRadio)

pedzik=createPed(217,-2352.69921875,-1609.96875,483.62594604492,255)
pedzia=createPed(211,-2353.142578125,-1611.509765625,483.63046264648,255)
setPedFrozen(pedzik, true)
setPedFrozen(pedzia, true)
setPedAnimation(pedzik, "RAPPING", "RAP_A_loop", -1, true, false, false, false)
setPedAnimation(pedzia, "DANCING", "dnce_M_a", -1, true, false, false, false)

function cancelIt()
if (source == pedzik) or (source == pedzia) then
 cancelEvent()
end
end

addEventHandler("onClientPedDamage", root, cancelIt)

meta = ""

addEventHandler("onClientSoundChangedMeta", root, function(streamTitle)
meta = streamTitle 
end)

addEventHandler( 'onClientRender', getRootElement(),
  function()
     -- if isElementStreamedIn( v ) then
          local x = -2340.37109
		  local y = -1620.31042
		  local z = 487.5880
          local cx, cy, cz = getCameraMatrix()
          if isLineOfSightClear( cx, cy, cz, x, y, z, false, false, true, false, false, false, false ) then
            local dist = getDistanceBetweenPoints3D( cx, cy, cz, x, y, z )
            if dist >= 3 and dist <= 10 then
              local px, py = getScreenFromWorldPosition( x, y, z, 0.06 )
              if px then
				dxDrawText( "Teraz gramy: "..meta, px + 2, py + 2, px, py, tocolor( 0, 0, 0, 255 ), 1, "default-bold", "center", "center" )
				dxDrawText( "Teraz gramy: "..meta, px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "default-bold", "center", "center" )
			end
          --end
        end
      end
    end
)

showPlayerHudComponent ( "clock", false
)